package com.itlong.cloud.operate.service.impl;

import com.alibaba.fastjson.JSON;
import com.itlong.cloud.POJO.DTO.operate.OperateDeviceInfoGetPageDTO;
import com.itlong.cloud.POJO.DTO.operate.OperateHardwareDeviceUpdateDTO;
import com.itlong.cloud.POJO.DTO.operate.OperateHardwareProjectGetPageDTO;
import com.itlong.cloud.POJO.PO.*;
import com.itlong.cloud.POJO.VO.operate.OperateDeviceInfoVO;
import com.itlong.cloud.POJO.VO.operate.OperateProjectInfoVO;
import com.itlong.cloud.POJO.VO.operate.OperateUpdateDetailVO;
import com.itlong.cloud.POJO.VO.operate.OperateUpdateInfoVO;
import com.itlong.cloud.POJO.VO.property.CloudElevatorByProjectIdVO;
import com.itlong.cloud.POJO.VO.property.PropertyProjectUnitInfoVO;
import com.itlong.cloud.PlatformConstants;
import com.itlong.cloud.commons.dao.ICloudTalkPushCloudIntercomChangeLogDao;
import com.itlong.cloud.commons.dao.IPushCloudElevatorChangeLogDao;
import com.itlong.cloud.commons.dao.IPushCloudEntranceChangeLogDao;
import com.itlong.cloud.enumerate.DataStatusEnum;
import com.itlong.cloud.enumerate.PushCloudEntranceChangeEnum;
import com.itlong.cloud.enumerate.PushCloudIntercomChangeEnum;
import com.itlong.cloud.enumerate.PushElevatorChangeEnum;
import com.itlong.cloud.operate.dao.IOperateHardwareDao;
import com.itlong.cloud.operate.dao.IOperatePackageDao;
import com.itlong.cloud.operate.dao.OperationSpecialLogDao;
import com.itlong.cloud.operate.service.IOperateHardwareService;
import com.itlong.cloud.property.dao.IPadFaceSyncDataServiceDao;
import com.itlong.cloud.utils.data.handler.SqlUtil;
import com.itlong.cloud.utils.page.Page;
import com.itlong.cloud.utils.random.LogicIdUtil;
import com.itlong.cloud.utils.words.StringHandlerUtil;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * <desc>
 *      运营-固件升级-设备升级服务接口实现类。
 * <desc/>
 *
 * @createDate 2018/08/27.
 */
@Service
public class IOperateHardwareServiceImpl implements IOperateHardwareService {

    private static final Logger LOG = LoggerFactory.getLogger(IOperateHardwareServiceImpl.class);

    @Autowired
    IOperateHardwareDao iOperateHardwareDao;

    @Autowired
    ICloudTalkPushCloudIntercomChangeLogDao iCloudTalkPushCloudIntercomChangeLogDao;

    @Autowired
    IPushCloudElevatorChangeLogDao iPushCloudElevatorChangeLogDao;

    @Autowired
    IPushCloudEntranceChangeLogDao iPushCloudEntranceChangeLogDao;

    @Autowired
    IOperatePackageDao iOperatePackageDao;

    @Autowired
    IPadFaceSyncDataServiceDao iPadFaceSyncDataServiceDao;

    @Autowired
    OperationSpecialLogDao operationSpecialLogDao;

    /**
     * <desc>
     *      分页获取设备信息。
     * <desc/>
     *
     * @param  operateUpdateInfoGetPageDTO 参数请求对象
     * @return
     * @author Qiang.S
     * @createDate 2018/08/27
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Page<OperateDeviceInfoVO> getDeviceInfoPage(OperateDeviceInfoGetPageDTO operateUpdateInfoGetPageDTO) throws Exception{

        //将DTO转换为Map params
        Map<String, Object> params = SqlUtil.convertBeanToMapParams(operateUpdateInfoGetPageDTO);
        //分页类默认pageSize为20
        Page<OperateDeviceInfoVO> page = new Page<>();
        page.getPage().setPageSize(operateUpdateInfoGetPageDTO.getPageSize());
        page.getPage().setCurrentPage(operateUpdateInfoGetPageDTO.getCurrentPage());
        params.put("status","".equals(operateUpdateInfoGetPageDTO.getStatus())?null:operateUpdateInfoGetPageDTO.getStatus().split(","));
        params.put("deviceUniqueList",("".equals(operateUpdateInfoGetPageDTO.getDeviceUniqueList())||operateUpdateInfoGetPageDTO.getDeviceUniqueList()==null)?null:operateUpdateInfoGetPageDTO.getDeviceUniqueList().split(","));
        params.put("projectId",operateUpdateInfoGetPageDTO.getProjectId().split(","));
        params.put("currentPage",page.getPage().getStartSlip());
        params.put("pageSize",page.getPage().getPageSize());
        //填充返回数据集 设备类别(2云门禁;3,云对讲;4人脸识别仪;5群控群，7 一体式人脸识别门禁,12云电梯;23云联动器
        if ("3".equals(operateUpdateInfoGetPageDTO.getDeviceKind())) {
            page.setRows(iOperateHardwareDao.getDeviceIntercomInfoPage(params),iOperateHardwareDao.getDeviceIntercomInfoCount(params));
        }
        if ("12".equals(operateUpdateInfoGetPageDTO.getDeviceKind())) {
            List<OperateDeviceInfoVO> infoPage = iOperateHardwareDao.getDeviceElevatorInfoPage(params);


            page.setRows(infoPage,iOperateHardwareDao.getDeviceElevatorInfoCount(params));
        }
        if ("2".equals(operateUpdateInfoGetPageDTO.getDeviceKind())) {
            //组装设备来源字段
            List<OperateDeviceInfoVO> infoPage = iOperateHardwareDao.getDeviceEntranceInfoPage(params);


            Integer count = iOperateHardwareDao.getDeviceEntranceInfoCount(params);
            page.setRows(infoPage,count);
        }
        if ("23".equals(operateUpdateInfoGetPageDTO.getDeviceKind())) {

            //组装设备来源字段
            List<OperateDeviceInfoVO> infoPage =  iOperateHardwareDao.getDeviceWippenInfoPage(params);
            page.setRows(infoPage, iOperateHardwareDao.getDeviceWippenInfoCount(params));
        }
        if ("5".equals(operateUpdateInfoGetPageDTO.getDeviceKind())) {
            page.setRows(iOperateHardwareDao.getDeviceClusterInfoPage(params),iOperateHardwareDao.getDevicClusterInfoCount(params));
        }
        if ("4".equals(operateUpdateInfoGetPageDTO.getDeviceKind())) {
            page.setRows(iOperateHardwareDao.getDevicePadInfoPage(params),iOperateHardwareDao.getDevicePadInfoCount(params));
        }
        if ("24".equals(operateUpdateInfoGetPageDTO.getDeviceKind())) {

            //组装设备来源字段
            List<OperateDeviceInfoVO> infoPage =  iOperateHardwareDao.getDeviceUnibodyFaceInfoPage(params);

            page.setRows(infoPage, iOperateHardwareDao.getDeviceUnibodyFaceInfoCount(params));
        }



        return page;
    }

    /**
     * <desc>
     *      根据项目编号获取设备更新时间
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Qiang.S
     * @createDate 2018-09-04
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public String getUpgradeTimeByProjectId(String projectId) throws Exception{
        return iOperateHardwareDao.getUpgradeTimeByProjectId(projectId);
    }

    /**
     * <desc>
     *      按条件分页获取项目列表
     * <desc/>
     *
     * @param operateHardwareProjectGetPageDTO 查询参数DTO
     * @return
     * @author Qiang.S
     * @createDate 2018-08-28
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Page<OperateProjectInfoVO> getProjectInfoPage(OperateHardwareProjectGetPageDTO operateHardwareProjectGetPageDTO) throws Exception{

        //将DTO转换为Map params
        Map<String, Object> params = SqlUtil.convertBeanToMapParams(operateHardwareProjectGetPageDTO);
        //分页类默认pageSize为20
        Page<OperateProjectInfoVO> page = new Page<>();
        page.getPage().setPageSize(operateHardwareProjectGetPageDTO.getPageSize());
        page.getPage().setCurrentPage(operateHardwareProjectGetPageDTO.getCurrentPage());
        params.put("currentPage",page.getPage().getStartSlip());
        params.put("pageSize",page.getPage().getPageSize());
        //填充返回数据集
        page.setRows(iOperateHardwareDao.getProjectInfoPage(params),iOperateHardwareDao.getProjectInfoCount(params));
        return page;
    }

    /**
     * <desc>
     *      按条件分页获取项目列表
     * <desc/>
     *
     * @param projectId 项目编号
     * @return
     * @author Qiang.S
     * @createDate 2018-08-28
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<PropertyProjectUnitInfoVO> getBuildInfo(String projectId) throws Exception{
        return iOperateHardwareDao.getBuildInfo(projectId);
    }

    /**
     * <desc>
     *      获取项目单元信息
     * <desc/>
     *
     * @param projectId 项目编号
     * @param buildId 楼栋编号
     * @return
     * @author Qiang.S
     * @createDate 2018-08-28
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public List<PropertyProjectUnitInfoVO> getUnitInfo(String projectId, String buildId) throws Exception{
        return iOperateHardwareDao.getUnitInfo(projectId,buildId);
    }

    /**
     * <desc>
     *      设置项目设备更新时间
     * <desc/>
     *
     * @param projectId 项目编号
     * @param upgradeTime 项目设备升级时间
     * @return
     * @author Qiang.S
     * @createDate 2018-08-28
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Integer setupUpdateTime(String projectId, String upgradeTime) throws Exception{
        return iOperateHardwareDao.setupUpdateTime(projectId,upgradeTime);
    }

    /**
     * <desc>
     *      设备更新
     * <desc/>
     *
     * @param operateHardwareDeviceUpdateDTO 设备更新信息
     * @return
     * @author Qiang.S
     * @createDate 2018-08-28
     */
    @Override
    @Transactional(propagation = Propagation.NOT_SUPPORTED)
    public Integer deviceUpdate(OperateHardwareDeviceUpdateDTO operateHardwareDeviceUpdateDTO) throws Exception{
        Date nowTime = new Date();
        //待升级设备唯一编号
        String[] deviceUnique = operateHardwareDeviceUpdateDTO.getDeviceUniques().split(",");
        OperateUpdateDetailVO vo = iOperatePackageDao.getUpdateDetail(operateHardwareDeviceUpdateDTO.getUpdateId());
        if ("3".equals(operateHardwareDeviceUpdateDTO.getDeviceKind())) {//云对讲
            List<DeviceCloudIntercomInfoPO> clouds = iOperateHardwareDao.getCloudIntercomsByDeviceUnique(deviceUnique);
            List<PushCloudIntercomChangeLogPO> projects=new ArrayList<>();
            for (DeviceCloudIntercomInfoPO cloud : clouds) {
                //云对讲指令表 push_cloud_intercom_change_log
                PushCloudIntercomChangeLogPO po = new PushCloudIntercomChangeLogPO();
                po.setCommandType(PushCloudIntercomChangeEnum.PUSH_UPDATE.getType());
                po.setCommandId(LogicIdUtil.bussinessId());
                po.setCommandData(operateHardwareDeviceUpdateDTO.getUpdateId());
                po.setDeviceUnique(cloud.getDeviceUnique());
                po.setSn(cloud.getSn());
                po.setStatus(0);
                po.setCreateTime(new Date());
                po.setUpgradeTime(operateHardwareDeviceUpdateDTO.getUpgradeTime());
                po=(PushCloudIntercomChangeLogPO) StringHandlerUtil.formatString(po);
                projects.add(po);
                //新增操作日志
                OperateUserInfoPO operateUserInfoPO = operationSpecialLogDao.getOperateUserPO(operateHardwareDeviceUpdateDTO.getLoginUserId());
                OperationSpecialLogPO operationSpecialLogPO = new OperationSpecialLogPO();
                operationSpecialLogPO.setLogId(LogicIdUtil.bussinessId());
                operationSpecialLogPO.setRealName(operateUserInfoPO.getRealName());
                operationSpecialLogPO.setAccount(operateUserInfoPO.getUserName());
                operationSpecialLogPO.setOuterId(cloud.getDeviceUnique());
                operationSpecialLogPO.setIp(operateHardwareDeviceUpdateDTO.getIp());
                operationSpecialLogPO.setOperateFunction(operateHardwareDeviceUpdateDTO.getOperateFunction());
                operationSpecialLogPO.setOperateWay(operateHardwareDeviceUpdateDTO.getOperateWay());
                operationSpecialLogPO.setFunctionType(6);
                operationSpecialLogPO.setOperateDec(operateUserInfoPO.getRealName() + "升级了"+ cloud.getDeviceUnique() +"设备"+"" +
                        ",原版本号："+(cloud.getApk()==null?"":cloud.getApk())+(cloud.getLinuxAppVer()==null?"":cloud.getLinuxAppVer())+"升至"+vo.getVersion()+"版本");
                operationSpecialLogPO.setStatus(DataStatusEnum.NORMAL.getType());
                operationSpecialLogPO.setCreateTime(nowTime);
                operationSpecialLogPO.setUpdateTime(nowTime);
                operationSpecialLogDao.save(SqlUtil.durableData(operationSpecialLogPO,PlatformConstants.TABLE_SAVE));

            }
            if (!projects.isEmpty()) {
                if (operateHardwareDeviceUpdateDTO.getUpgradeTime() == null || "".equals(operateHardwareDeviceUpdateDTO.getUpgradeTime())) {
                    iCloudTalkPushCloudIntercomChangeLogDao.batchSave(projects);
                }else {
                    iCloudTalkPushCloudIntercomChangeLogDao.batchSaveAndUpgradeTime(projects);
                }
            }
        }
        if ("12".equals(operateHardwareDeviceUpdateDTO.getDeviceKind()) || "5".equals(operateHardwareDeviceUpdateDTO.getDeviceKind())) {//云电梯,群控器
            List<CloudElevatorByProjectIdVO> clouds = null;
            if ("12".equals(operateHardwareDeviceUpdateDTO.getDeviceKind())) {
                clouds = iOperateHardwareDao.getCloudElevatorByDeviceUnique(deviceUnique);
            }else if ("5".equals(operateHardwareDeviceUpdateDTO.getDeviceKind())) {
                clouds = iOperateHardwareDao.getCloudClusterByDeviceUnique(deviceUnique);
            }
            List<PushCloudElevatorChangeLogPO> projects=new ArrayList<>();
            //云电梯指令表  push_cloud_elevator_change_log
            for (CloudElevatorByProjectIdVO cloud : clouds) {
                //查询项目信息
                PushCloudElevatorChangeLogPO po = new PushCloudElevatorChangeLogPO();
                po.setCommandType(PushElevatorChangeEnum.PUSH_UPDATE.getType());
                po.setCommandId(LogicIdUtil.bussinessId());
                po.setCommandData(operateHardwareDeviceUpdateDTO.getUpdateId());
                po.setDeviceUnique(cloud.getDeviceUnique());
                po.setSn(cloud.getSn());
                po.setStatus(DataStatusEnum.NORMAL.getType());
                po.setCommandStatus(DataStatusEnum.DELETE.getType());
                po.setCreateTime(new Date());
                po.setUpgradeTime(operateHardwareDeviceUpdateDTO.getUpgradeTime());
                po=(PushCloudElevatorChangeLogPO) StringHandlerUtil.formatString(po);
                projects.add(po);
                //新增操作日志
                OperateUserInfoPO operateUserInfoPO = operationSpecialLogDao.getOperateUserPO(operateHardwareDeviceUpdateDTO.getLoginUserId());
                OperationSpecialLogPO operationSpecialLogPO = new OperationSpecialLogPO();
                operationSpecialLogPO.setLogId(LogicIdUtil.bussinessId());
                operationSpecialLogPO.setRealName(operateUserInfoPO.getRealName());
                operationSpecialLogPO.setAccount(operateUserInfoPO.getUserName());
                operationSpecialLogPO.setOuterId(cloud.getDeviceUnique());
                operationSpecialLogPO.setIp(operateHardwareDeviceUpdateDTO.getIp());
                operationSpecialLogPO.setOperateFunction(operateHardwareDeviceUpdateDTO.getOperateFunction());
                operationSpecialLogPO.setOperateWay(operateHardwareDeviceUpdateDTO.getOperateWay());
                operationSpecialLogPO.setFunctionType(6);
                operationSpecialLogPO.setOperateDec(operateUserInfoPO.getRealName() + "升级了"+cloud.getDeviceUnique() +"设备"+"" +
                        ",原版本号："+(cloud.getVersion()==null?"":cloud.getVersion())+"升至"+vo.getVersion()+"版本");   operationSpecialLogPO.setStatus(DataStatusEnum.NORMAL.getType());
                operationSpecialLogPO.setCreateTime(nowTime);
                operationSpecialLogPO.setUpdateTime(nowTime);
                operationSpecialLogDao.save(SqlUtil.durableData(operationSpecialLogPO,PlatformConstants.TABLE_SAVE));
            }
            if (!projects.isEmpty()) {
                if (operateHardwareDeviceUpdateDTO.getUpgradeTime() == null || "".equals(operateHardwareDeviceUpdateDTO.getUpgradeTime())) {
                    iPushCloudElevatorChangeLogDao.batchSave(projects);
                }else {
                    iPushCloudElevatorChangeLogDao.batchSaveAndUpgradeTime(projects);
                }
            }
        }
        if ("2".equals(operateHardwareDeviceUpdateDTO.getDeviceKind()) || "23".equals(operateHardwareDeviceUpdateDTO.getDeviceKind())
                || "24".equals(operateHardwareDeviceUpdateDTO.getDeviceKind())) {//云门禁或联动器
            //待升级设备唯一编号
            String[] sn = operateHardwareDeviceUpdateDTO.getSn().split(",");
            List<DeviceEntranceInfoPO> clouds;
            if ("2".equals(operateHardwareDeviceUpdateDTO.getDeviceKind())) {
                clouds = iOperateHardwareDao.getCloudEntranceBySn(sn);
            }else  if ("24".equals(operateHardwareDeviceUpdateDTO.getDeviceKind())) {
                clouds = iOperateHardwareDao.getCloudUnibodyFaceBySn(sn);
            }else {
                clouds = iOperateHardwareDao.getCloudWippenBySn(sn);
            }
            List<PushCloudEntranceChangeLogPO> projects=new ArrayList<>();
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            //云门禁指令表  push_cloud_entrance_change_log
            for (DeviceEntranceInfoPO cloud : clouds) {
                //查询项目信息
                PushCloudEntranceChangeLogPO po = new PushCloudEntranceChangeLogPO();
                po.setCommandType(PushCloudEntranceChangeEnum.PUSH_UPDATE.getType());
                po.setCommandId(LogicIdUtil.bussinessId());
                po.setCommandData(operateHardwareDeviceUpdateDTO.getUpdateId());
                po.setDeviceUnique(cloud.getDeviceUnique());
                po.setSn(cloud.getBindDeviceGroup());
                po.setStatus(DataStatusEnum.NORMAL.getType());
                po.setCommandStatus(DataStatusEnum.DELETE.getType());
                po.setCreateTime(new Date());
                if (operateHardwareDeviceUpdateDTO.getUpgradeTime() != null && !"".equals(operateHardwareDeviceUpdateDTO.getUpgradeTime())) {
                    po.setUpgradeTime(sdf.parse(operateHardwareDeviceUpdateDTO.getUpgradeTime()));
                }
                po=(PushCloudEntranceChangeLogPO) StringHandlerUtil.formatString(po);
                projects.add(po);
                //新增操作日志
                OperateUserInfoPO operateUserInfoPO = operationSpecialLogDao.getOperateUserPO(operateHardwareDeviceUpdateDTO.getLoginUserId());
                OperationSpecialLogPO operationSpecialLogPO = new OperationSpecialLogPO();
                operationSpecialLogPO.setLogId(LogicIdUtil.bussinessId());
                operationSpecialLogPO.setRealName(operateUserInfoPO.getRealName());
                operationSpecialLogPO.setAccount(operateUserInfoPO.getUserName());
                operationSpecialLogPO.setOuterId(cloud.getDeviceUnique());
                operationSpecialLogPO.setIp(operateHardwareDeviceUpdateDTO.getIp());
                operationSpecialLogPO.setOperateFunction(operateHardwareDeviceUpdateDTO.getOperateFunction());
                operationSpecialLogPO.setOperateWay(operateHardwareDeviceUpdateDTO.getOperateWay());
                operationSpecialLogPO.setFunctionType(6);
                operationSpecialLogPO.setOperateDec(operateUserInfoPO.getRealName() + "升级了"+ cloud.getDeviceUnique() +"设备"+"" +
                        ",原版本号："+(cloud.getVersion()==null?"":cloud.getVersion())+"升至"+vo.getVersion()+"版本");   operationSpecialLogPO.setStatus(DataStatusEnum.NORMAL.getType());
                operationSpecialLogPO.setStatus(DataStatusEnum.NORMAL.getType());
                operationSpecialLogPO.setCreateTime(nowTime);
                operationSpecialLogPO.setUpdateTime(nowTime);
                operationSpecialLogDao.save(SqlUtil.durableData(operationSpecialLogPO,PlatformConstants.TABLE_SAVE));
            }
            if (!projects.isEmpty()) {
                if (operateHardwareDeviceUpdateDTO.getUpgradeTime() == null || "".equals(operateHardwareDeviceUpdateDTO.getUpgradeTime())) {
                    iPushCloudEntranceChangeLogDao.batchSave(projects);
                }else {
                    iPushCloudEntranceChangeLogDao.batchSaveAndUpgradeTime(projects);
                }
            }
        }
        if ("4".equals(operateHardwareDeviceUpdateDTO.getDeviceKind())) {//人脸识别仪
            List<DevicePadInfoPO> clouds = iOperateHardwareDao.getCloudPadByDeviceUnique(deviceUnique);
            List<PadPullCloudInfoPO> projects=new ArrayList<>();
           // OperateUpdateDetailVO vo = iOperatePackageDao.getUpdateDetail(operateHardwareDeviceUpdateDTO.getUpdateId());
            for (DevicePadInfoPO cloud : clouds) {
                //人脸识别仪指令表 pad_pull_cloud_info
                PadPullCloudInfoPO po = new PadPullCloudInfoPO();
                po.setDeviceUnique(cloud.getDeviceUnique());
                po.setProjectId(cloud.getDeviceUnique().substring(0,8));
                po.setSyncData(operateHardwareDeviceUpdateDTO.getUpdateId());
                po.setSyncType(2);
                po.setSyncSerialNo(LogicIdUtil.bussinessId());
                po.setDataType(4);
                po.setSyncStatus(1);
                po.setStatus(DataStatusEnum.NORMAL.getType());
                po.setCreateTime(new Date());
                //设备更新
                po.setInstructionType(19);
                po.setSourceSystem(3);
                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                if (operateHardwareDeviceUpdateDTO.getUpgradeTime() != null && !"".equals(operateHardwareDeviceUpdateDTO.getUpgradeTime())) {
                    po.setUpgradeTime(sdf.parse(operateHardwareDeviceUpdateDTO.getUpgradeTime()));
                }
                po=(PadPullCloudInfoPO) StringHandlerUtil.formatString(po);
                projects.add(po);

                //新增操作日志
                OperateUserInfoPO operateUserInfoPO = operationSpecialLogDao.getOperateUserPO(operateHardwareDeviceUpdateDTO.getLoginUserId());
                OperationSpecialLogPO operationSpecialLogPO = new OperationSpecialLogPO();
                operationSpecialLogPO.setLogId(LogicIdUtil.bussinessId());
                operationSpecialLogPO.setRealName(operateUserInfoPO.getRealName());
                operationSpecialLogPO.setAccount(operateUserInfoPO.getUserName());
                operationSpecialLogPO.setOuterId(cloud.getDeviceUnique());
                operationSpecialLogPO.setIp(operateHardwareDeviceUpdateDTO.getIp());
                operationSpecialLogPO.setOperateFunction(operateHardwareDeviceUpdateDTO.getOperateFunction());
                operationSpecialLogPO.setOperateWay(operateHardwareDeviceUpdateDTO.getOperateWay());
                operationSpecialLogPO.setFunctionType(6);
                operationSpecialLogPO.setOperateDec(operateUserInfoPO.getRealName() + "升级了"+cloud.getDeviceUnique()+"设备"+"" +
                        ",原版本号："+(cloud.getVersion()==null?"":cloud.getVersion())+"升至"+vo.getVersion()+"版本");   operationSpecialLogPO.setStatus(DataStatusEnum.NORMAL.getType());
                operationSpecialLogPO.setStatus(DataStatusEnum.NORMAL.getType());
                operationSpecialLogPO.setCreateTime(nowTime);
                operationSpecialLogPO.setUpdateTime(nowTime);
                operationSpecialLogDao.save(SqlUtil.durableData(operationSpecialLogPO,PlatformConstants.TABLE_SAVE));
            }
            if (!projects.isEmpty()) {
                //清除沉余指令
                iPadFaceSyncDataServiceDao.deletePullDataByDeviceType(projects,vo.getDeviceType());
                if (operateHardwareDeviceUpdateDTO.getUpgradeTime() == null || "".equals(operateHardwareDeviceUpdateDTO.getUpgradeTime())) {
                    iPadFaceSyncDataServiceDao.batchSave(projects);
                }else {
                    iPadFaceSyncDataServiceDao.batchSaveAndUpgradeTime(projects);
                }
            }
        }
        return null;
    }


    /**
     * <desc>
     * 通过设备类型查询安装包
     * </desc>
     *
     * @param productTypes
     * @Author chengshican
     * @Date 2020-11-12 10:22
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public List<OperateUpdateInfoVO> getPackageNameByProductType(String productTypes,String deviceType) throws Exception {
        String[] arr=productTypes.split(",");
        return iOperateHardwareDao.getPackageNameByProductType(arr,deviceType);
    }

    /**
     * <desc>
     * 通过设备唯一标识符获取云对讲详细信息接口
     * </desc>
     *
     * @param deviceUnique
     * @Author chengshican
     * @Date 2020-11-16 14:39
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public OperateDeviceInfoVO getTalkeDetailByDeviceUnique(String deviceUnique) throws Exception {
        return iOperateHardwareDao.getTalkeDetailByDeviceUnique(deviceUnique);
    }

    /**
     * <desc>
     * 通过设备唯一标识符获取云电梯详细信息接口
     * </desc>
     *
     * @param deviceUnique
     * @Author chengshican
     * @Date 2020-11-16 14:39
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public OperateDeviceInfoVO getElevatorDetailByDeviceUnique(String deviceUnique) throws Exception {
        return iOperateHardwareDao.getElevatorDetailByDeviceUnique(deviceUnique);
    }

    /**
     * <desc>
     * 通过设备唯一标识符获取云门禁详细信息接口
     * </desc>
     *
     * @param deviceUnique
     * @Author chengshican
     * @Date 2020-11-16 14:39
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public OperateDeviceInfoVO getEntranceDetailByDeviceUnique(String deviceUnique) throws Exception {
        return iOperateHardwareDao.getEntranceDetailByDeviceUnique(deviceUnique);
    }

    /**
     * <desc>
     * 通过设备唯一标识符获取群控器详细信息接口
     * </desc>
     *
     * @param deviceUnique
     * @Author chengshican
     * @Date 2020-11-16 14:40
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public OperateDeviceInfoVO getClusterDetailByDeviceUnique(String deviceUnique) throws Exception {
        return iOperateHardwareDao.getClusterDetailByDeviceUnique(deviceUnique);
    }

    /**
     * <desc>
     * 通过设备唯一标识符获取联动器详细信息接口
     * </desc>
     *
     * @param deviceUnique
     * @Author chengshican
     * @Date 2020-11-16 14:40
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public OperateDeviceInfoVO getWippenDetailByDeviceUnique(String deviceUnique) throws Exception {
        return iOperateHardwareDao.getWippenDetailByDeviceUnique(deviceUnique);
    }

    /**
     * <desc>
     * 通过设备唯一标识符获取一体式门禁详细信息接口
     * </desc>
     *
     * @param deviceUnique
     * @Author chengshican
     * @Date 2020-11-16 14:40
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public OperateDeviceInfoVO getUnibodyDetailByDeviceUnique(String deviceUnique) throws Exception {
        return iOperateHardwareDao.getUnibodyDetailByDeviceUnique(deviceUnique);
    }

    /**
     * <desc>
     * 通过设备唯一标识符获取平板详细信息接口
     * </desc>
     *
     * @param deviceUnique
     * @Author chengshican
     * @Date 2020-11-16 14:40
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public OperateDeviceInfoVO getPadDetailByDeviceUnique(String deviceUnique) throws Exception {
        return iOperateHardwareDao.getPadDetailByDeviceUnique(deviceUnique);
    }

    /**
     * <desc>
     * 查询云门禁是否绑定地址
     * </desc>
     *
     * @param deviceUnique
     * @Author chengshican
     * @Date 2020-12-03 13:45
     * @Param deviceUnique 设备唯一标识
     * @Return
     * @Exception
     */
    @Override
    public Integer getEntranceDeviceAddressByUnique(String deviceUnique) throws Exception {
        return iOperateHardwareDao.getEntranceDeviceAddressByUnique(deviceUnique);
    }

    /**
     * <desc>
     * 查询云电梯是否绑定地址
     * </desc>
     *
     * @param deviceUnique
     * @Author chengshican
     * @Date 2020-12-03 13:46
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public Integer getElevatorDeviceAddressByUnique(String deviceUnique) throws Exception {
        return iOperateHardwareDao.getElevatorDeviceAddressByUnique(deviceUnique);
    }

    /**
     * <desc>
     * 获取受限设备云电梯
     * </desc>
     *
     * @Author chengshican
     * @Date 2020-12-07 10:14
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public List<String> getSpElevatorList() throws Exception {
        return iOperateHardwareDao.getSpElevatorList();
    }

    /**
     * <desc>
     * 受限设备云群控
     * </desc>
     *
     * @Author chengshican
     * @Date 2020-12-07 10:16
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public List<String> getSpControllerList() throws Exception {
        return iOperateHardwareDao.getSpControllerList();
    }

    /**
     * <desc>
     *
     * @Description </desc>
     * @Author chengshican
     * @Date 2020-12-07 10:17
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public List<String> getSpPadList() throws Exception {
        return iOperateHardwareDao.getSpPadList();
    }

    /**
     * <desc>
     * 受限设备云门禁
     * </desc>
     *
     * @Author chengshican
     * @Date 2020-12-07 10:18
     * @Param
     * @Return
     * @Exception
     */
    @Override
    public List<String> getSpEntranceList() throws Exception {
        return iOperateHardwareDao.getSpEntranceList();
    }


}
